package models;

import java.util.Date;
import java.util.List;

import siena.Column;
import siena.DateTime;
import siena.Generator;
import siena.Id;
import siena.Model;
import siena.Query;
import siena.Table;

@Table("posts")
public class Post extends Model {

	@Id(Generator.AUTO_INCREMENT)
	public Long id;

	@Column("title")
	public String title;

	@DateTime
	public Date postedAt=new Date();

	@Column("content")
	public String content;

	@Column("comments")
	public List<Comment> comments;
	
	public Post(String title, String content) {
		this.title = title;
		this.content = content;
	}
	
	

	public String toString() {
		return "title  = "+title+", content = "+content;
	}
	
	public static Post findById(Long id){
		return Model.all(Post.class).filter("id", id).get();
	}

	public static Query<Post> all() {
		return Model.all(Post.class);
	}

}